<meta name="content-type" content="text/html; charset=UTF-8" />
<div class="panel-heading panel-result-title">
	<h3 class="panel-title">查询结果</h3>
	<div class="btn-group btn-group-sm btn-gp-default">
		<button id="btn_create" type="button"
			class="btn btn-default panel-radius-left">添加</button>
		<button id="btn_edit" type="button"
			class="btn btn-default panel-radius-none">修改</button>
		<button id="btn_delete" type="button"
			class="btn btn-default panel-radius-none">删除</button>
		<button id="btn_role" type="button"
			class="btn btn-default panel-radius-none">指定角色</button>
		<button id="btn_hall" type="button"
			class="btn btn-default panel-radius-right">指定会馆</button>
	</div>
</div>
<!-- #set(PaginatedList<Group> groups) -->
<!--
		#set(
		pager = groups.pager,
		totalResults = pager.getCountOfTotalResults(),
		totalPages = pager.getCountOfTotalPages() * 1,
		pageSize = pager.pageSize,
		pageNo = pager.pageNo,
		prePageNo = pager.getPrevPageNo(),
		nextPageNo = pager.getNextPageNo()
		)
-->
<!--#if(groups)-->
<table class="table table-bordered table-hover table-condensed tb"
	style="text-align: center; border-bottom: 1px solid #DDDDDD;">
	<tr>
		<td width="100"><input id="chkallIds" type="checkbox" /></td>
		<td width="250">英文名称</td>
		<td width="250">中文名称</td>
		<td>描述</td>
	<tr>
		<!--#for(Group group : groups)-->
	<tr>
		<td><input name="chk_name" type="checkbox" value="${group.id}" /></td>
		<td>${group.name}</td>
		<td>${group.namecn}</td>
		<td>${group.description}</td>
	</tr>
	<!--#end-->
</table>

<!-- #else -->
<div class="panel-body">没有符合条件的数据</div>

<!-- #end -->
<!-- 列表分页 -->
<div class="paging-page">$!{include("paging_page.html")}</div>
<form action="yueyogaAdmin/grantRoles.jhtml" method="post"
	name="roleForm">
	<div id="ubl_userRole" class="panel-dialog-box panel-radius-all"
		style="width: 420px; display: none; z-index: 1000; min-height: 200px;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">指定角色</h3>
			<br> <br>
			<label class="col-sm-1 control-label">当前角色</label> 
			<label id="roles" style="width: 275px !important;" class="col-sm-1 control-label"></label> 
			<br><br>
			<input type="hidden" id=groupId name="groupId" /> 
			<label for="selUserRoles" class="col-sm-1 control-label">重定角色</label>
			<div class="col-sm-8">
				<!-- #set(List<Role> groupRole) -->
				<select class="selectpicker show-menu-arrow" multiple data-width="100%" name="roleId" id="selUserRoles">
					<option value="">请选择</option>
					<!--#for(Role g: groupRole)-->
					<option value="${g.id}">${g.name}</option>
					<!-- #end -->
				</select>
			</div>
			
			<div class="panel-btn-search" style="float: left; text-align: right; margin-top: 20px; margin-left: 110px;">
				<button type="button" id="btn_ok1" class="btn-adet-default">保存</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_close" onclick="closeRoleDIV()" class="btn-adet-default">取消</button>
			</div>
		</div>
	</div>
</form>
<form action="yueyogaAdmin/grantHall.jhtml" method="post"
	name="hallForm">
	<div id="ubl_userHall" class="panel-dialog-box panel-radius-all"
		style="width: 420px; height: 200px !important; display: none; z-index: 1000; min-height: 200px;">
		<div class="panel-heading panel-result-title">
			<h3 class="panel-title">指定会馆</h3>
			<br> <br>
			<label class="col-sm-1 control-label">当前会馆</label> 
			<label id="halls" style="width: 275px !important;" class="col-sm-1 control-label"></label> 
			<br> <br> 
			<input type="hidden" id="hid_groupId" name="groupId" /> 
			<label for="selUserHall" class="col-sm-1 control-label">重定会馆</label>
			<div class="col-sm-8">
				<!-- #set(List<Hall> halls) -->
				<select class="selectpicker show-menu-arrow" multiple data-width="100%" name="hallId" id="selUserHall">
					<option value=""></option>
					<!--#for(Hall h: halls)-->
					<option value="${h.code}">${h.name}</option>
					<!-- #end -->
				</select>
			</div>
			<div class="panel-btn-search" style="float: left; text-align: right; margin-top: 20px; margin-left: 110px;">
				<button type="button" id="btn_ok2" class="btn-adet-default">保存</button>
				&nbsp;&nbsp;&nbsp;
				<button type="button" id="btn_close" onclick="closeHallDIV()" class="btn-adet-default">取消</button>
			</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	function documentReady() {
		var groupMsg = "${groupMsg}";
		if (groupMsg == "success") {
			var d = alert("指定成功");
			setTimeout(function() {
				d.close().remove();
			}, 1000);
		} else if (groupMsg == "failure") {
			error("指定失败");
		}
		
		$("#txtUserEnabled").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
	}
	function closeRoleDIV() {
		$("#ubl_userRole").slideToggle(0);
	}
	function closeHallDIV() {
		$("#ubl_userHall").slideToggle(0);
	}
	$(function() {
		var ids = [];

		//指定角色
		$("#btn_ok1").click(function() {
			var role = $("#selUserRoles").select2("val") + "";
			if (role.length > 0 && role) {
				//document.roleForm.submit();
				$("form[name='roleForm']").submit();
			} else {
				closeRoleDIV();
				alert("请选择指定角色!!");
			}
		});

		$("#btn_ok2").click(function() {
			var hall = $("#selUserHall").select2("val") + "";
			if (hall.length > 0 && hall) {
				//document.hallForm.submit();
				$("form[name='hallForm']").submit();
			} else {
				closeHallDIV();
				alert("请选择指定会馆!");
			}
		});
		$("#btn_no").click(function() {
			$("li").empty();
			$("#ugl_role").hide();
		});

		$("#btn_role").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			
			if (ids.length == 0 || ids.length > 1) {
				alert("请选择一个用户组,指定角色!");
				ids = [];
				return;
			} else {
				$("#selUserRoles").select2("val", "");
				closeRoleDIV();
				$("#groupId").val(ids);
				var url = "yueyogaAdmin/findUserRoleById.jhtml";
				$("#ugl_group").show();
				var ops = '';
				$.post(url, {
					"gpId" : ids[0]
				}, function(resp) {
					var data = eval('(' + resp + ')');
					var str = '';
					var msg = eval('(' + data.msg + ')');
					if (data.success) {
						$.each(msg, function(i, val) {
							str = str + val.name + ',';
						});
						str = str.substring(0, str.length - 1);
						$("#roles").text(str);
					}
				});
				ids = [];
			}
		});

		$("#btn_hall").click(function() {
			$('input[name="chk_name"]:checked').each(function() {
				ids.push($(this).val());
			});
			if (ids.length == 0 || ids.length > 1) {
				alert("请选择一个用户组,指定会馆!");
				ids = [];
				return;
			} else {
				$("#selUserHall").select2("val", "");
				closeHallDIV();
				$("#hid_groupId").val(ids);
				var url = "yueyogaAdmin/findUserHallById.jhtml";
				$("#ugl_group").show();
				var ops = '';
				$.post(url, {
					"groupId" : ids[0]
				}, function(resp) {
					var data = eval('(' + resp + ')');
					var str = '';
					var msg = eval('(' + data.msg + ')');
					if (data.success) {
						$.each(msg, function(i, val) {
							str = str + val.name + ',';
						});
						str = str.substring(0, str.length - 1);
						$("#halls").text(str);
					}
				});
				ids = [];
			}
		});
		//删除
		$("#btn_delete").click(function btn_delete() {
			var deleteId = document.getElementsByName("chk_name");
			var ids = "";
			for ( var i = 0; i < deleteId.length; i++) {
				if (deleteId[i].checked) {
					ids = ids + deleteId[i].value + ","
				}
			}
			if (ids.length == 0) {
				alert("请选择您要删除的记录!");
			} else {
				confirm('确定要删除吗？',function(){
					ids = ids.substring(0, ids.length - 1);
					var url = "yueyogaAdmin/deleteGroup.jhtml?ids=" + ids;
					$.post(url, function(response) {
						if (response) {
							alert("删除成功!");
							//window.location.href="yueyogaAdmin/searchGroupUsers.jhtml"
							$("form[name='taskForm']").submit();
						} else {
							alert("删除失败!");
						}
					}, "json");
				});
			}

		});
		//--全选`反选
		$("#chkallIds").click(function() {
			if (this.checked) {
				$("input[name='chk_name']").each(function() {
					this.checked = true;
				});
			} else {
				$("input[name='chk_name']").each(function() {
					this.checked = false;
				});
			}
		});
		//添加
		$("#btn_create").click(function() {
			window.location.href = "yueyogaAdmin/toAddGroupUser.jhtml";
		});
		//修改
		$("#btn_edit")
				.click(
						function() {
							var id = $('input[name="chk_name"]:checked');
							if (id.length == 1) {
								window.location.href = "yueyogaAdmin/toUpdateGroupUser.jhtml?userId="
										+ id.val();
							} else {
								alert("请选择一行进行修改!");
							}
						});
	});
	function changePage(value) {
		value = value * 1;
		var totalPages = '${totalPages}';
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		$("#txtPageNumber").val(value);
		goToPage(value);
	}
	function goToPage(pageNo) {
		$("#hidPageNo").val(pageNo);
		document.taskForm.submit();
	}
</script>